// src/stores/settings.ts
import {defineStore} from 'pinia';

type SettingField = {
    key: string;
    label: string;
    type: 'string' | 'number' | 'boolean' | 'select';
    default: unknown;
    options?: Array<{ label: string; value: string | number }>;
    category: string;
};

export const useSettingsStore = defineStore('settings', {
    state: () => ({
        fields: [
            {
                key: 'selectedModel',
                label: '选择模型',
                type: 'select',
                default: 'deepseek-chat',
                options: [
                    {label: 'DeepSeek V3', value: 'deepseek-chat'},
                    {label: 'DeepSeek R1', value: 'deepseek-reasoner'},
                    {label: 'DeepSeek-R1' + ' 7B', value: 'deepseek-r1:7b'},
                    {label: 'DeepSeek-R1' + ' 8B', value: 'deepseek-r1:8b'},
                    {label: 'DeepSeek-R1' + ' 1.5B', value: 'deepseek-r1:1.5b'},
                ],
                category: '模型设置',
            },
            {
                key: 'useStream',
                label: '流式输出',
                type: 'boolean',
                default: false,
                category: '模型设置',
            },
            {
                key: 'genHywayJs',
                label: 'hyway脚本助手',
                type: 'boolean',
                default: false,
                category: '模型设置',
            },
            {
                key: 'maxTokens',
                label: '最大 Tokens',
                type: 'number',
                default: 2048,
                category: '高级设置',
            },
            {
                key: 'apiKey',
                label: 'API 密钥',
                type: 'string',
                default: '',
                category: '高级设置',
            },
        ] as SettingField[],
        values: {} as Record<string, unknown>, // 存储字段的实际值
    }),
    actions: {
        // 初始化字段值
        initializeValues() {
            this.fields.forEach((field) => {
                if (this.values[field.key] === undefined) {
                    this.values[field.key] = field.default;
                }
            });
        },
        // 更新字段值
        setValue(key: string, value: unknown) {
            this.values[key] = value;
        },
    },
});
